package cn.itsource.crm.web.controller;

import cn.itsource.AjaxResult;
import cn.itsource.PageList;
import cn.itsource.crm.domain.*;
import cn.itsource.crm.query.DepartmentQuery;
import cn.itsource.crm.query.OrderFormQuery;
import cn.itsource.crm.service.IOrderFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/order")
@Api(tags = "维修单接口类") //给前端看的
@CrossOrigin//解决跨域问题
public class OrderFormController {

    @Autowired
    private IOrderFormService orderFormService;

    //获取太监列表 指定获取方式-path
    @RequestMapping(value = "/list",method = RequestMethod.PATCH)
    @ResponseBody//把对象转成json格式
    @ApiResponses({//给前端看的
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=500,message="服务器错误")
    })
    @ApiOperation(value="查询所有皇帝信息",notes = "queryAll查询方法")//给前端看的
    @CrossOrigin//解决跨域问题
    public List<OrderForm> queryAll(){
        return orderFormService.queryAll();
    }

    //获取维修单列表 根据客户id
    @RequestMapping(value = "/kh/{id}",method = RequestMethod.PATCH)
    @ResponseBody//把对象转成json格式
    @ApiResponses({//给前端看的
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=500,message="服务器错误")
    })
    @ApiOperation(value="查询客户所有维修单信息",notes = "queryAll_kh查询方法")//给前端看的
    @CrossOrigin//解决跨域问题
    public List<OrderForm> queryAll_kh(@PathVariable Long id){
        return orderFormService.queryAll_kh(id);
    }

    //查询单条 维修单id
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ApiOperation(value="根据ID查询类型",notes = "queryOne查询方法")
    @ResponseBody
    public OrderForm getOne(@PathVariable Long id){
        return orderFormService.queryOne(id);
    }


    @RequestMapping(value = "/save",method = RequestMethod.PUT)
    @ResponseBody
    @ApiOperation(value="保存太监",notes = "save方法")
    public AjaxResult save(@RequestBody OrderForm OrderForm){//接收前端json数据
        try {
            orderFormService.save(OrderForm);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult("保存失败");
        }
        return new AjaxResult();
    }



    //修改
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value="修改客户方法",notes = "update方法")
    public AjaxResult update(@RequestBody  OrderForm orderForm){
        try {
            orderFormService.update(orderForm);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult("修改失败");
        }
        return new AjaxResult();
    }

    //删除
    @RequestMapping(value = "{id}",method = RequestMethod.DELETE)
    @ResponseBody
    @CrossOrigin
    @ApiOperation(value="根据id删除字典类型及type对应的明细",notes = "delete方法")
    public AjaxResult delete(@PathVariable Long id){
        try {
            orderFormService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult("删除失败");

        }
        return new AjaxResult();
    }

    //分页查询方法
    @RequestMapping(value = "/queryPage",method = RequestMethod.PATCH)
    @ResponseBody
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=500,message="服务器错误")
    })
    @CrossOrigin
    public PageList queryPage(@RequestBody OrderFormQuery orderFormQuery){
        return orderFormService.queryPage(orderFormQuery);
    }

    //获取所有维修员
    @RequestMapping(value = "/list_repair",method = RequestMethod.PATCH)
    @ResponseBody//把对象转成json格式
    @ApiResponses({//给前端看的
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=500,message="服务器错误")
    })
    @ApiOperation(value="查询所有维修员",notes = "queryAll查询方法")//给前端看的
    @CrossOrigin//解决跨域问题
    public List<F_Reqair> list_repair(){
        return orderFormService.list_repair();
    }

    //获取所有售后
    @RequestMapping(value = "/list_after_seller",method = RequestMethod.PATCH)
    @ResponseBody//把对象转成json格式
    @ApiResponses({//给前端看的
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=500,message="服务器错误")
    })
    @ApiOperation(value="查询所有售后员",notes = "queryAll查询方法")//给前端看的
    @CrossOrigin//解决跨域问题
    public List<F_after_seller> list_after_seller(){
        return orderFormService.list_after_seller();
    }
}
